package com.youkeda.exercise.api;

import com.youkeda.comment.model.Result;
import com.youkeda.exercise.model.ProductDetail;
import com.youkeda.exercise.service.ProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/api/productDetail")
@Controller
public class ProductDetailApi {

    @Autowired
    private ProductDetailService productDetailService;

    @GetMapping("/productId")
    @ResponseBody
    public Result<List<ProductDetail>> get(@RequestParam("productId") String productId){
        Result<List<ProductDetail>> result = new Result<>();
        List<ProductDetail> list = productDetailService.getByProductId(productId);
        if (!list.isEmpty()){
            result.setSuccess(true);
        }
        result.setData(list);
        return result;
    }
}
